<?PHP

class AdminBO extends BusinessObject{
  
  /* private function using in constructors*/ 
  function setAttributes(){
    $this->fields   = array(
                      'id'        =>  'adminID',
                      'login'     =>  'adminLogin',
                      'password'  =>  'adminPassword',
                      'firstname' =>  'adminFirstname',
                      'lastname'  =>  'adminLastname',
                      'email'     =>  'adminEmail',
                      'region'    =>  'adminRegion',
                      'deleted'   =>  'adminDeleted',
                      'disabled'  =>  'adminDisabled',
                      'sa'        =>  'adminSA');

    BusinessObject::setAttributes();
  }  
  /* constructor */
  function AdminBO(){
    /** super(tableName) */
    BusinessObject::BusinessObject("admins");
    $this->setAttributes();
  }
  
  function checkLogin(){
    $a = new AdminBO();
    $a->login = $this->login;
    if($this->id){
      $where = $a->fields[id]."<>".$this->id;
    }
    return($a->getCount($where)==0);
  }
  
  /*  Save  */
  function Save($adminID){
    if(is_numeric($adminID) && $adminID<>0){
      $this->id = "$adminID";
      if(!($this->checkLogin())) return (" Admin with login '{$this->login}' is already exist");
      $this->Update("{$this->fields[id]} = '$adminID'");  
    } else{
      if(!($this->checkLogin())) return (" Admin with login '{$this->login}' is already exist");
      $this->Insert();
      $this->id = $this->getInsertID();
    }
  }
}
?>
